<?php
/**
 * Created by PhpStorm.
 * User: zyark
 * Date: 2018/4/2
 * Time: 08:35
 */

namespace app\index\controller;


use app\common\controller\Frontend;
use app\common\utils\Constant;
use app\index\logic\WithdrawLogic;

class Withdrawal extends Frontend
{
    /**
     * ajax提现
     * @return \think\response\Json
     */
    public function ajax_withdrawal(){
        $check = $this->check();
        if(!$check['success']){
            return $this->returnJson($check['msg'],$check['code']);
        }
        $user_id = $check['user_id'];
        $money = $this->request->post('money');
        $logic = new WithdrawLogic();
        $result = $logic->withdrawal($money,$user_id);
        $code = 0;
        $msg = '';
        $data = [];
        switch ($result['status']){
            case 0:
                $code = Constant::CODE_ERROR;
                $msg = '提现申请失败！';
                $data = $result['error'];
                break;
            case 1:
                $code = Constant::CODE_SUCCESS;
                $msg = '提现申请成功，请等待管理员审核！';
                break;
            case 2:
                $code = Constant::CODE_ERROR;
                $msg = $result['msg'];
                break;
            case 3:
                $code = Constant::CODE_INSUFFICIENT_FUNDS;
                $msg = '账户余额不足！';
                break;
        }
        return $this->returnJson($msg,$code,$data);
    }
}